Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[다리 건너기] 김민겸 미션 제출합니다. #9

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

Mingyum-Kim
Copy link

No description provided.

Comment on lines +26 to +42
public void printMap(List<Move> moves) {
List<String> up = new ArrayList<>();
List<String> down = new ArrayList<>();
for (Move move : moves) {
if (move.direction().equals("U")) {
up.add(move.success());
down.add(NONE);
}
if (move.direction().equals("D")) {
up.add(NONE);
down.add(move.success());
}
}
ConsoleWriter.printlnMessage(generateSingleMapRow(up));
ConsoleWriter.printlnMessage(generateSingleMapRow(down));
ConsoleWriter.println();
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수가 너무 길다! 어떻게 해결할 수 있을까?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void printMap(List<Move> moves) {
List<String> up = new ArrayList<>();
List<String> down = new ArrayList<>();
for (Move move : moves) {
if (move.direction().equals("U")) {
up.add(move.success());
down.add(NONE);
}
if (move.direction().equals("D")) {
up.add(NONE);
down.add(move.success());
}
}
ConsoleWriter.printlnMessage(generateSingleMapRow(up));
ConsoleWriter.printlnMessage(generateSingleMapRow(down));
ConsoleWriter.println();
}
public void printMap(List<Move> moves) {
List<String> up = new ArrayList<>();
List<String> down = new ArrayList<>();
for (Move move : moves) {
moveUp(up, down, move);
moveDown(up, down, move);
}
ConsoleWriter.printlnMessage(generateSingleMapRow(up));
ConsoleWriter.printlnMessage(generateSingleMapRow(down));
ConsoleWriter.println();
}
private void moveDown(List<String> up, List<String> down, Move move) {
if (move.direction().equals("D")) {
up.add(NONE);
down.add(move.success());
}
}
private void moveUp(List<String> up, List<String> down, Move move) {
if (move.direction().equals("U")) {
up.add(move.success());
down.add(NONE);
}
}

Comment on lines +18 to +27
public static void validateRange(
int number,
int start,
int end,
ErrorMessage errorMessage
) {
if (isInvalidRange(number, start, end)) {
throw CustomException.from(errorMessage);
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드의 파라미터는 최대 3개까지만 허용한다.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이러한 경우 에러 메시지를 범위 검증에 맞는 것을 따로 만들고, 에러 메시지에 대한 파라미터를 지우는 것을 차선책으로 한다

Comment on lines +72 to +74
return new Move(direction, "X");
}
return new Move(direction, "O");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

컨트롤러에서 뷰 단의 출력까지 책임지고 있는 형태이다.
boolean 등의 변수로 넘긴 다음에 뷰에서 분기하여 O, X를 출력하는 것이 바람직하다

Comment on lines +44 to +54
public String generateSingleMapRow(List<String> map) {
int size = map.size();
if (size == 1) {
return "[ " + map.get(0) + " ]";
}
String head = "[ " + map.get(0);
for (int i = 1; i < size; i++) {
head += String.format(SINGLE_MAP_FORMAT, map.get(i));
}
return head + " ]";
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringJoiner로 간결하게 작성할 수 있다.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public String generateSingleMapRow(List<String> map) {
int size = map.size();
if (size == 1) {
return "[ " + map.get(0) + " ]";
}
String head = "[ " + map.get(0);
for (int i = 1; i < size; i++) {
head += String.format(SINGLE_MAP_FORMAT, map.get(i));
}
return head + " ]";
}
public String generateSingleMapRow(List<String> map) {
String result = new StringJoiner(" | ", "[", "]");
for(String mp : map) {
result.add(mp);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant